package de.zainodis.commons.component.ui.widget;

import static junit.framework.Assert.assertNotNull;

import java.util.Calendar;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

/**
 * Fragment can be used to display a date picker dialog.
 * 
 * @author fzarrai
 * 
 */
public class DatePickerFragment extends DialogFragment {

   private static final String TAG = "DatePickerFragment";

   private final DatePickerDialog.OnDateSetListener onDone;

   public DatePickerFragment() {
	 onDone = null;
   }

   public DatePickerFragment(DatePickerDialog.OnDateSetListener onClick) {
	 assertNotNull(TAG
		  + " must be provided with an instance of DatePickerDialog.OnDateSetListener", onClick);
	 this.onDone = onClick;
   }

   @Override
   public Dialog onCreateDialog(Bundle savedInstanceState) {
	 // Use the current date as the default date in the picker
	 final Calendar c = Calendar.getInstance();
	 int year = c.get(Calendar.YEAR);
	 int month = c.get(Calendar.MONTH);
	 int day = c.get(Calendar.DAY_OF_MONTH);

	 return new DatePickerDialog(getActivity(), onDone, year, month, day);
   }

}
